Commit 269e91c6 by Igor Ovsyannikov Committed by Sébastien Eustace

Typing syntax fixes (#1156)

* Typing syntax fixes

* Fix some function signatures that were messing with ellipsis
  for example, `fun(a, ...)` is not valid, but `fun(...)` is

* Dict value types - is that legal? (puzzle/provider.py)

* Ignore assigning instance to classes
  (singletons like Infinity in version/utils.py)

* Add basic mypy config

This configuration has all common settings like:

* strict Optional in functions that returns None

* ignore missing imports - this is usual thing

* Check code that has no typing annotation but uses typed classes/functions
parent f43ef050
[mypy]
check_untyped_defs = True
ignore_errors = False
ignore_missing_imports = True
strict_optional = True
warn_unused_ignores = True
warn_redundant_casts = True
warn_unused_configs = True
...@@ -33,7 +33,11 @@ class Config: ...@@ -33,7 +33,11 @@ class Config:
def content(self): def content(self):
return self._content return self._content
def setting(self, setting_name, default=None): # type: (str) -> Any def setting(
self,
setting_name, # type: str
default=None,
):
""" """
Retrieve a setting value. Retrieve a setting value.
""" """
......
...@@ -181,8 +181,8 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in ...@@ -181,8 +181,8 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
f.write(content) f.write(content)
def _determine_requirements( def _determine_requirements(
self, requires, allow_prereleases=False # type: List[str] # type: bool self, requires, allow_prereleases=False
): # type: (...) -> List[str] ): # type: (List[str], bool) -> List[str]
if not requires: if not requires:
requires = [] requires = []
......
...@@ -28,8 +28,11 @@ class ApplicationConfig(BaseApplicationConfig): ...@@ -28,8 +28,11 @@ class ApplicationConfig(BaseApplicationConfig):
self.add_event_listener(ConsoleEvents.PRE_HANDLE.value, self.set_env) self.add_event_listener(ConsoleEvents.PRE_HANDLE.value, self.set_env)
def register_command_loggers( def register_command_loggers(
self, event, event_name, _ self,
): # type: (PreHandleEvent, str, ...) -> None event, # type: PreHandleEvent
event_name, # type: str
_,
): # type: (...) -> None
command = event.command.config.handler command = event.command.config.handler
if not isinstance(command, Command): if not isinstance(command, Command):
return return
...@@ -56,7 +59,7 @@ class ApplicationConfig(BaseApplicationConfig): ...@@ -56,7 +59,7 @@ class ApplicationConfig(BaseApplicationConfig):
logger.setLevel(level) logger.setLevel(level)
def set_env(self, event, event_name, _): # type: (PreHandleEvent, str, ...) -> None def set_env(self, event, event_name, _): # type: (PreHandleEvent, str, _) -> None
from poetry.semver import parse_constraint from poetry.semver import parse_constraint
from poetry.utils.env import EnvManager from poetry.utils.env import EnvManager
......
...@@ -22,7 +22,12 @@ from .base_installer import BaseInstaller ...@@ -22,7 +22,12 @@ from .base_installer import BaseInstaller
class PipInstaller(BaseInstaller): class PipInstaller(BaseInstaller):
def __init__(self, env, io, pool): # type: (Env, ...) -> None def __init__(
self,
env, # type: Env
io,
pool,
): # type: (...) -> None
self._env = env self._env = env
self._io = io self._io = io
self._pool = pool self._pool = pool
......
...@@ -235,7 +235,7 @@ class Builder(object): ...@@ -235,7 +235,7 @@ class Builder(object):
return dict(result) return dict(result)
@classmethod @classmethod
def convert_author(cls, author): # type: () -> dict def convert_author(cls, author): # type: (...) -> dict
m = AUTHOR_REGEX.match(author) m = AUTHOR_REGEX.match(author)
name = m.group("name") name = m.group("name")
......
...@@ -267,7 +267,9 @@ class SdistBuilder(Builder): ...@@ -267,7 +267,9 @@ class SdistBuilder(Builder):
@classmethod @classmethod
def convert_dependencies( def convert_dependencies(
cls, package, dependencies # type: Package # type: List[Dependency] cls,
package, # type: Package
dependencies, # type: List[Dependency]
): ):
main = [] main = []
extras = defaultdict(list) extras = defaultdict(list)
......
...@@ -26,7 +26,7 @@ class PackageInclude(Include): ...@@ -26,7 +26,7 @@ class PackageInclude(Include):
def is_package(self): # type: () -> bool def is_package(self): # type: () -> bool
return self._is_package return self._is_package
def is_module(self): # type: () def is_module(self): # type: () -> bool
return self._is_module return self._is_module
def refresh(self): # type: () -> PackageInclude def refresh(self): # type: () -> PackageInclude
......
...@@ -134,7 +134,7 @@ class Locker(object): ...@@ -134,7 +134,7 @@ class Locker(object):
return packages return packages
def set_lock_data(self, root, packages): # type: () -> bool def set_lock_data(self, root, packages): # type: (...) -> bool
hashes = {} hashes = {}
packages = self._lock_packages(packages) packages = self._lock_packages(packages)
# Retrieving hashes # Retrieving hashes
......
...@@ -55,7 +55,12 @@ class Provider: ...@@ -55,7 +55,12 @@ class Provider:
UNSAFE_PACKAGES = {"setuptools", "distribute", "pip"} UNSAFE_PACKAGES = {"setuptools", "distribute", "pip"}
def __init__(self, package, pool, io): # type: (Package, Pool, ...) -> None def __init__(
self,
package, # type: Package
pool, # type: Pool
io,
): # type: (...) -> None
self._package = package self._package = package
self._pool = pool self._pool = pool
self._io = io self._io = io
......
...@@ -215,12 +215,13 @@ class Solver: ...@@ -215,12 +215,13 @@ class Solver:
marker = intersection marker = intersection
childrens = [] # type: List[Dict[str, Any]]
graph = { graph = {
"name": package.name, "name": package.name,
"category": category, "category": category,
"optional": optional, "optional": optional,
"marker": marker, "marker": marker,
"children": [], # type: List[Dict[str, Any]] "children": childrens,
} }
if previous_dep and previous_dep is not dep and previous_dep.name == dep.name: if previous_dep and previous_dep is not dep and previous_dep.name == dep.name:
...@@ -259,7 +260,7 @@ class Solver: ...@@ -259,7 +260,7 @@ class Solver:
# If there is already a child with this name # If there is already a child with this name
# we merge the requirements # we merge the requirements
existing = None existing = None
for child in graph["children"]: for child in childrens:
if ( if (
child["name"] == pkg.name child["name"] == pkg.name
and child["category"] == dependency.category and child["category"] == dependency.category
...@@ -280,7 +281,7 @@ class Solver: ...@@ -280,7 +281,7 @@ class Solver:
) )
continue continue
graph["children"].append(child_graph) childrens.append(child_graph)
return graph return graph
......
import re import re
from typing import List from typing import List
from typing import Union from typing import Optional
from .empty_constraint import EmptyConstraint from .empty_constraint import EmptyConstraint
from .exceptions import ParseVersionError from .exceptions import ParseVersionError
...@@ -19,14 +19,14 @@ class Version(VersionRange): ...@@ -19,14 +19,14 @@ class Version(VersionRange):
def __init__( def __init__(
self, self,
major, # type: int major, # type: int
minor=None, # type: Union[int, None] minor=None, # type: Optional[int]
patch=None, # type: Union[int, None] patch=None, # type: Optional[int]
rest=None, # type: Union[int, None] rest=None, # type: Optional[int]
pre=None, # type: Union[str, None] pre=None, # type: Optional[str]
build=None, # type: Union[str, None] build=None, # type: Optional[str]
text=None, # type: Union[str, None] text=None, # type: Optional[str]
precision=None, # type: Union[int, None] precision=None, # type: Optional[int]
): # type: () -> None ): # type: (...) -> None
self._major = int(major) self._major = int(major)
self._precision = None self._precision = None
if precision is None: if precision is None:
......
...@@ -26,7 +26,8 @@ _trans_op = { ...@@ -26,7 +26,8 @@ _trans_op = {
def parse( def parse(
version, strict=False # type: str # type: bool version, # type: str
strict=False, # type: bool
): # type:(...) -> Union[Version, LegacyVersion] ): # type:(...) -> Union[Version, LegacyVersion]
""" """
Parse the given version string and return either a :class:`Version` object Parse the given version string and return either a :class:`Version` object
......
...@@ -27,7 +27,7 @@ class Infinity(object): ...@@ -27,7 +27,7 @@ class Infinity(object):
return NegativeInfinity return NegativeInfinity
Infinity = Infinity() Infinity = Infinity() # type: ignore
class NegativeInfinity(object): class NegativeInfinity(object):
...@@ -59,4 +59,4 @@ class NegativeInfinity(object): ...@@ -59,4 +59,4 @@ class NegativeInfinity(object):
return Infinity return Infinity
NegativeInfinity = NegativeInfinity() NegativeInfinity = NegativeInfinity() # type: ignore
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment