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:
def content(self):
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.
"""
......
......@@ -181,8 +181,8 @@ The <info>init</info> command creates a basic <comment>pyproject.toml</> file in
f.write(content)
def _determine_requirements(
self, requires, allow_prereleases=False # type: List[str] # type: bool
): # type: (...) -> List[str]
self, requires, allow_prereleases=False
): # type: (List[str], bool) -> List[str]
if not requires:
requires = []
......
......@@ -28,8 +28,11 @@ class ApplicationConfig(BaseApplicationConfig):
self.add_event_listener(ConsoleEvents.PRE_HANDLE.value, self.set_env)
def register_command_loggers(
self, event, event_name, _
): # type: (PreHandleEvent, str, ...) -> None
self,
event, # type: PreHandleEvent
event_name, # type: str
_,
): # type: (...) -> None
command = event.command.config.handler
if not isinstance(command, Command):
return
......@@ -56,7 +59,7 @@ class ApplicationConfig(BaseApplicationConfig):
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.utils.env import EnvManager
......
......@@ -22,7 +22,12 @@ from .base_installer import 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._io = io
self._pool = pool
......
......@@ -235,7 +235,7 @@ class Builder(object):
return dict(result)
@classmethod
def convert_author(cls, author): # type: () -> dict
def convert_author(cls, author): # type: (...) -> dict
m = AUTHOR_REGEX.match(author)
name = m.group("name")
......
......@@ -267,7 +267,9 @@ class SdistBuilder(Builder):
@classmethod
def convert_dependencies(
cls, package, dependencies # type: Package # type: List[Dependency]
cls,
package, # type: Package
dependencies, # type: List[Dependency]
):
main = []
extras = defaultdict(list)
......
......@@ -26,7 +26,7 @@ class PackageInclude(Include):
def is_package(self): # type: () -> bool
return self._is_package
def is_module(self): # type: ()
def is_module(self): # type: () -> bool
return self._is_module
def refresh(self): # type: () -> PackageInclude
......
......@@ -134,7 +134,7 @@ class Locker(object):
return packages
def set_lock_data(self, root, packages): # type: () -> bool
def set_lock_data(self, root, packages): # type: (...) -> bool
hashes = {}
packages = self._lock_packages(packages)
# Retrieving hashes
......
......@@ -55,7 +55,12 @@ class Provider:
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._pool = pool
self._io = io
......
......@@ -215,12 +215,13 @@ class Solver:
marker = intersection
childrens = [] # type: List[Dict[str, Any]]
graph = {
"name": package.name,
"category": category,
"optional": optional,
"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:
......@@ -259,7 +260,7 @@ class Solver:
# If there is already a child with this name
# we merge the requirements
existing = None
for child in graph["children"]:
for child in childrens:
if (
child["name"] == pkg.name
and child["category"] == dependency.category
......@@ -280,7 +281,7 @@ class Solver:
)
continue
graph["children"].append(child_graph)
childrens.append(child_graph)
return graph
......
import re
from typing import List
from typing import Union
from typing import Optional
from .empty_constraint import EmptyConstraint
from .exceptions import ParseVersionError
......@@ -19,14 +19,14 @@ class Version(VersionRange):
def __init__(
self,
major, # type: int
minor=None, # type: Union[int, None]
patch=None, # type: Union[int, None]
rest=None, # type: Union[int, None]
pre=None, # type: Union[str, None]
build=None, # type: Union[str, None]
text=None, # type: Union[str, None]
precision=None, # type: Union[int, None]
): # type: () -> None
minor=None, # type: Optional[int]
patch=None, # type: Optional[int]
rest=None, # type: Optional[int]
pre=None, # type: Optional[str]
build=None, # type: Optional[str]
text=None, # type: Optional[str]
precision=None, # type: Optional[int]
): # type: (...) -> None
self._major = int(major)
self._precision = None
if precision is None:
......
......@@ -26,7 +26,8 @@ _trans_op = {
def parse(
version, strict=False # type: str # type: bool
version, # type: str
strict=False, # type: bool
): # type:(...) -> Union[Version, LegacyVersion]
"""
Parse the given version string and return either a :class:`Version` object
......
......@@ -27,7 +27,7 @@ class Infinity(object):
return NegativeInfinity
Infinity = Infinity()
Infinity = Infinity() # type: ignore
class NegativeInfinity(object):
......@@ -59,4 +59,4 @@ class NegativeInfinity(object):
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