Skip to content

Commit

Permalink
Add pyupgrade pre-commit config
Browse files Browse the repository at this point in the history
Also configure it to run as part of tox checks, add some Black config
  • Loading branch information
graingert committed Feb 9, 2021
1 parent 7aa8d7e commit 95b8a15
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 42 deletions.
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.9.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]

- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
args: ["--target-version=py36"]

- repo: https://github.com/pycqa/isort
rev: 5.7.0
hooks:
- id: isort
args: ["--profile=black"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.2.2
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: mixed-line-ending
2 changes: 1 addition & 1 deletion asgiref/current_thread_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from concurrent.futures import Executor, Future


class _WorkItem(object):
class _WorkItem:
"""
Represents an item needing to be run in the executor.
Copied from ThreadPoolExecutor (but it's private, so we're not going to rely on importing it)
Expand Down
6 changes: 3 additions & 3 deletions asgiref/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, thread_critical: bool = False) -> None:
self._context_refs: "weakref.WeakSet[object]" = weakref.WeakSet()
# Random suffixes stop accidental reuse between different Locals,
# though we try to force deletion as well.
self._attr_name = "_asgiref_local_impl_%s_%s" % (
self._attr_name = "_asgiref_local_impl_{}_{}".format(
id(self),
"".join(random.choice(string.ascii_letters) for i in range(8)),
)
Expand Down Expand Up @@ -104,7 +104,7 @@ def __getattr__(self, key):
if key in storage:
return storage[key]
else:
raise AttributeError("%r object has no attribute %r" % (self, key))
raise AttributeError(f"{self!r} object has no attribute {key!r}")

def __setattr__(self, key, value):
if key in ("_context_refs", "_thread_critical", "_thread_lock", "_attr_name"):
Expand All @@ -119,4 +119,4 @@ def __delattr__(self, key):
if key in storage:
del storage[key]
else:
raise AttributeError("%r object has no attribute %r" % (self, key))
raise AttributeError(f"{self!r} object has no attribute {key!r}")
2 changes: 1 addition & 1 deletion asgiref/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ async def application_exception(self, exception, application_details):
"Exception inside application: %s\n%s%s",
exception,
"".join(traceback.format_tb(exception.__traceback__)),
" {}".format(exception),
f" {exception}",
)
2 changes: 1 addition & 1 deletion asgiref/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ async def __call__(self, *args, **kwargs):
sys.exc_info(),
func,
*args,
**kwargs
**kwargs,
),
)
ret = await asyncio.wait_for(future, timeout=None)
Expand Down
2 changes: 1 addition & 1 deletion asgiref/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self,
timeout: Optional[float],
*,
loop: Optional[asyncio.AbstractEventLoop] = None
loop: Optional[asyncio.AbstractEventLoop] = None,
) -> None:
self._timeout = timeout
if loop is None:
Expand Down
51 changes: 25 additions & 26 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import List, Dict
from typing import Dict, List

#
# ASGI documentation build configuration file, created by
# sphinx-quickstart on Thu May 17 21:22:10 2018.
Expand Down Expand Up @@ -41,24 +41,24 @@
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'ASGI'
copyright = '2018, ASGI Team'
author = 'ASGI Team'
project = "ASGI"
copyright = "2018, ASGI Team"
author = "ASGI Team"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '3.0'
version = "3.0"
# The full version, including alpha/beta/rc tags.
release = '3.0'
release = "3.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -70,10 +70,10 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
Expand All @@ -84,7 +84,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'default'
html_theme = "default"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -95,7 +95,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -116,7 +116,7 @@
# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'ASGIdoc'
htmlhelp_basename = "ASGIdoc"


# -- Options for LaTeX output ---------------------------------------------
Expand All @@ -125,15 +125,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -143,19 +140,15 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'ASGI.tex', 'ASGI Documentation',
'ASGI Team', 'manual'),
(master_doc, "ASGI.tex", "ASGI Documentation", "ASGI Team", "manual"),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'asgi', 'ASGI Documentation',
[author], 1)
]
man_pages = [(master_doc, "asgi", "ASGI Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -164,7 +157,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'ASGI', 'ASGI Documentation',
author, 'ASGI', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"ASGI",
"ASGI Documentation",
author,
"ASGI",
"One line description of project.",
"Miscellaneous",
),
]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from setuptools import setup # type: ignore[import]

setup(name='asgiref')
setup()
4 changes: 2 additions & 2 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ async def test_wsgi_path_encoding():
"""
# Define WSGI app
def wsgi_application(environ, start_response):
assert environ["SCRIPT_NAME"] == "/中国".encode("utf8").decode("latin-1")
assert environ["PATH_INFO"] == "/中文".encode("utf8").decode("latin-1")
assert environ["SCRIPT_NAME"] == "/中国".encode().decode("latin-1")
assert environ["PATH_INFO"] == "/中文".encode().decode("latin-1")
start_response("200 OK", [])
yield b""

Expand Down
8 changes: 2 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ commands =
[testenv:qa]
skip_install=true
deps =
black
flake8
isort
pre-commit
commands =
flake8 asgiref tests
black --check asgiref tests
isort --check-only --diff asgiref tests
pre-commit {posargs:run --all-files --show-diff-on-failure}

0 comments on commit 95b8a15

Please sign in to comment.