Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing #261

Closed
5 of 6 tasks
danieleades opened this issue Feb 13, 2021 · 12 comments · Fixed by #298 or #517
Closed
5 of 6 tasks

Typing #261

danieleades opened this issue Feb 13, 2021 · 12 comments · Fixed by #298 or #517
Labels
❓ help wanted Extra attention is needed

Comments

@danieleades
Copy link
Contributor

danieleades commented Feb 13, 2021

I'm hoping to gradually improve the 'typing' in this library to the point where it can be linted using Mypy.

There's quite a lot to do first! This library uses a few loosely-typed data structures which lead to a lot of type errors. That will possibly involve some refactoring (or heavy use of if not None checks everywhere).

I'll use this is as a parent task for various efforts to improve the typing-

@frostming
Copy link
Collaborator

Thanks for pointing it out, I actually have no enough energy to enforce type annotations for the whole codebase. Contributions are welcomed of course.

@frostming frostming added the ❓ help wanted Extra attention is needed label Feb 17, 2021
@frostming frostming linked a pull request Mar 12, 2021 that will close this issue
@danieleades
Copy link
Contributor Author

for a sense of scale, here's the current output from mypy-

mypy output
pdm/formats/setup_py.py:13: error: Cannot find implementation or library stub for module named 'pdm.pep517.base'
pdm/project/metadata.py:3: error: Cannot find implementation or library stub for module named 'pdm.pep517.metadata'
pdm/models/readers.py:12: error: Need type annotation for 'DEFAULT'
pdm/models/readers.py:43: error: Incompatible return value type (got "Dict[str, Union[Dict[Any, Any], List[Any], None]]", expected "Dict[str, Union[List[Any], Dict[Any, Any]]]")
pdm/models/readers.py:54: error: Cannot find implementation or library stub for module named 'pdm.pep517.metadata'
pdm/models/readers.py:80: error: Incompatible types in assignment (expression has type "Optional[List[Any]]", variable has type "List[stmt]")
pdm/models/readers.py:82: error: Incompatible return value type (got "Dict[str, Union[Dict[Any, Any], List[Any], None]]", expected "Dict[str, Union[List[Any], Dict[Any, Any]]]")
pdm/models/readers.py:87: error: Incompatible types in assignment (expression has type "List[str]", target has type "Optional[str]")
pdm/models/readers.py:88: error: Incompatible types in assignment (expression has type "Dict[str, List[Any]]", target has type "Optional[str]")
pdm/models/readers.py:93: error: Incompatible return value type (got "Dict[str, Optional[str]]", expected "Dict[str, Union[List[Any], Dict[Any, Any]]]")
pdm/models/readers.py:111: error: Need type annotation for 'extras_require' (hint: "extras_require: Dict[<type>, <type>] = ...")
pdm/models/readers.py:137: error: Dict entry 0 has incompatible type "str": "Optional[str]"; expected "str": "Union[List[Any], Dict[Any, Any]]"
pdm/models/readers.py:138: error: Dict entry 1 has incompatible type "str": "Optional[str]"; expected "str": "Union[List[Any], Dict[Any, Any]]"
pdm/models/readers.py:141: error: Dict entry 4 has incompatible type "str": "Optional[str]"; expected "str": "Union[List[Any], Dict[Any, Any]]"
pdm/models/readers.py:168: error: Unsupported left operand type for + ("None")
pdm/models/readers.py:168: note: Left operand is of type "Optional[List[Any]]"
pdm/models/readers.py:182: error: "expr" has no attribute "id"
pdm/models/readers.py:201: error: Incompatible types in assignment (expression has type "Optional[Call]", variable has type "Tuple[Optional[Call], Optional[List[Any]]]")
pdm/models/readers.py:203: error: Unsupported operand types for + ("List[Any]" and "None")
pdm/models/readers.py:203: note: Right operand is of type "Optional[List[Any]]"
pdm/models/readers.py:205: error: Incompatible return value type (got "Tuple[Tuple[Optional[Call], Optional[List[Any]]], List[Any]]", expected "Tuple[Optional[Call], Optional[List[Any]]]")
pdm/models/readers.py:210: error: Need type annotation for 'install_requires' (hint: "install_requires: List[<type>] = ...")
pdm/models/readers.py:232: error: Argument 1 to "_find_in_dict" of "SetupReader" has incompatible type "_ast.Dict"; expected "Call"
pdm/models/readers.py:239: error: "expr" has no attribute "s"
pdm/models/readers.py:245: error: "expr" has no attribute "s"
pdm/models/readers.py:252: error: Need type annotation for 'extras_require' (hint: "extras_require: Dict[<type>, <type>] = ...")
pdm/models/readers.py:274: error: Argument 1 to "_find_in_dict" of "SetupReader" has incompatible type "_ast.Dict"; expected "Call"
pdm/models/readers.py:282: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "expr")
pdm/models/readers.py:285: error: Item "expr" of "Optional[expr]" has no attribute "s"
pdm/models/readers.py:285: error: Item "None" of "Optional[expr]" has no attribute "s"
pdm/models/readers.py:285: error: "expr" has no attribute "s"
pdm/models/readers.py:294: error: Incompatible types in assignment (expression has type "Optional[Any]", variable has type "expr")
pdm/models/readers.py:297: error: Item "expr" of "Optional[expr]" has no attribute "s"
pdm/models/readers.py:297: error: Item "None" of "Optional[expr]" has no attribute "s"
pdm/models/readers.py:297: error: "expr" has no attribute "s"
pdm/models/readers.py:301: error: Missing return statement
pdm/models/readers.py:310: error: Return value expected
pdm/models/readers.py:314: error: Return value expected
pdm/models/readers.py:318: error: Return value expected
pdm/models/readers.py:321: error: Return value expected
pdm/models/readers.py:325: error: Argument 1 to "_find_in_dict" of "SetupReader" has incompatible type "_ast.Dict"; expected "Call"
pdm/models/readers.py:328: error: Return value expected
pdm/models/readers.py:338: error: Missing return statement
pdm/models/readers.py:351: error: Missing return statement
pdm/models/readers.py:367: error: Missing return statement
pdm/models/readers.py:368: error: "Call" has no attribute "keys"
pdm/models/readers.py:368: error: "Call" has no attribute "values"
pdm/__init__.py:3: error: Cannot determine type of '__path__'
pdm/models/pip_shims.py:68: error: Name 'get_flag' already defined on line 61
pdm/models/pip_shims.py:124: error: Incompatible types in assignment (expression has type "Optional[str]", target has type "Tuple[int, int]")
pdm/models/pip_shims.py:126: error: Incompatible types in assignment (expression has type "List[Optional[str]]", target has type "Tuple[int, int]")
pdm/utils.py:35: error: Name 'cached_property' already defined (possibly by an import)
pdm/utils.py:43: error: Incompatible return value type (got "cached_property[_T]", expected "_T")
pdm/utils.py:60: error: List item 1 has incompatible type "Optional[str]"; expected "str"
pdm/utils.py:60: error: Argument 1 to "urlparse" has incompatible type "Union[str, bool]"; expected "str"
pdm/utils.py:69: error: List item 1 has incompatible type "Optional[str]"; expected "str"
pdm/utils.py:69: error: Argument 1 to "urlparse" has incompatible type "Union[str, bool]"; expected "str"
pdm/utils.py:201: error: Need type annotation for 'result' (hint: "result: Dict[<type>, <type>] = ...")
pdm/utils.py:409: error: Argument 1 to "relative_to" of "PurePath" has incompatible type "Optional[str]"; expected "Union[str, _PathLike[str]]"
pdm/iostream.py:20: error: Incompatible types in assignment (expression has type "Tuple[str, ...]", variable has type "Tuple[str, str, str, str, str, str, str, str]")
pdm/iostream.py:143: error: "IOStream" has no attribute "yellow"
pdm/iostream.py:156: error: Incompatible types in assignment (expression has type "Halo", variable has type "DummySpinner")
pdm/models/project_info.py:17: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:17: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:18: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:18: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:20: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:22: error: "IOStream" has no attribute "green"
pdm/models/project_info.py:23: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:23: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:25: error: Item "str" of "Union[str, List[str], Dict[<nothing>, <nothing>]]" has no attribute "get"
pdm/models/project_info.py:25: error: Item "List[str]" of "Union[str, List[str], Dict[<nothing>, <nothing>]]" has no attribute "get"
pdm/models/project_info.py:25: error: No overload variant of "get" of "Mapping" matches argument types "str", "Dict[<nothing>, <nothing>]"
pdm/models/project_info.py:25: note: Possible overload variant:
pdm/models/project_info.py:25: note:     def [_T] get(self, key: <nothing>, default: _T) -> _T
pdm/models/project_info.py:25: note:     <1 more non-matching overload not shown>
pdm/models/project_info.py:28: error: Need type annotation for 'author_contact'
pdm/models/project_info.py:31: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:32: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:33: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:33: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:34: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:34: error: Item "str" of "Union[str, List[str], Dict[<nothing>, <nothing>]]" has no attribute "get"
pdm/models/project_info.py:34: error: Item "List[str]" of "Union[str, List[str], Dict[<nothing>, <nothing>]]" has no attribute "get"
pdm/models/project_info.py:34: error: No overload variant of "get" of "Mapping" matches argument types "str", "Dict[<nothing>, <nothing>]"
pdm/models/project_info.py:34: note: Possible overload variant:
pdm/models/project_info.py:34: note:     def [_T] get(self, key: <nothing>, default: _T) -> _T
pdm/models/project_info.py:34: note:     <1 more non-matching overload not shown>
pdm/models/project_info.py:37: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:37: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:38: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:38: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:39: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:42: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:42: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:43: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:43: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:45: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:47: error: "IOStream" has no attribute "green"
pdm/models/project_info.py:48: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:48: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:49: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:49: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:50: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:50: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:51: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:51: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:52: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:52: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:53: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:54: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:55: error: Incompatible types in "yield" (actual type "Tuple[Any, Union[str, List[str]]]", expected type "Tuple[str, str]")
pdm/models/project_info.py:55: error: "IOStream" has no attribute "cyan"
pdm/models/project_info.py:57: error: Item "None" of "Union[str, List[str], None]" has no attribute "__iter__" (not iterable)
pdm/models/project_info.py:58: error: "IOStream" has no attribute "cyan"
pdm/project/config.py:44: error: Incompatible return value type (got "Union[str, bool]", expected "bool")
pdm/project/config.py:153: error: Need type annotation for 'toml_data' (hint: "toml_data: Dict[<type>, <type>] = ...")
pdm/project/config.py:175: error: Too many arguments
pdm/project/config.py:185: error: Too many arguments
pdm/project/config.py:189: error: "IOStream" has no attribute "yellow"
pdm/project/config.py:201: error: Return type "Iterable[str]" of "__iter__" incompatible with return type "Iterator[Any]" in supertype "Iterable"
pdm/project/config.py:214: error: "IOStream" has no attribute "yellow"
pdm/models/specifiers.py:22: error: Incompatible return value type (got "Tuple[object, ...]", expected "Tuple[Union[int, str], ...]")
pdm/models/specifiers.py:34: error: Argument 1 to <tuple> has incompatible type "*Tuple[Union[int, str], ...]"; expected "int"
pdm/models/specifiers.py:125: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:142: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:147: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:178: error: Argument 1 to "_version_part_match" has incompatible type "Tuple[Union[int, str], ...]"; expected "Tuple[int, ...]"
pdm/models/specifiers.py:178: error: Argument 2 to "_version_part_match" has incompatible type "Tuple[Union[int, str], ...]"; expected "Tuple[int, ...]"
pdm/models/specifiers.py:197: error: Argument 1 to "_version_part_match" has incompatible type "Tuple[Union[int, str], ...]"; expected "Tuple[int, ...]"
pdm/models/specifiers.py:200: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:208: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:221: error: Argument 1 to "_version_part_match" has incompatible type "Tuple[Union[int, str], ...]"; expected "Tuple[int, ...]"
pdm/models/specifiers.py:224: error: Incompatible types in assignment (expression has type "Tuple[int, ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:224: error: Argument 1 to "_complete_version" has incompatible type "Tuple[Union[int, str], ...]"; expected "Tuple[int, ...]"
pdm/models/specifiers.py:229: error: Incompatible types in assignment (expression has type "Tuple[Union[int, str], ...]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:288: error: Incompatible types in assignment (expression has type "Tuple[int, int]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:290: error: Incompatible types in assignment (expression has type "Tuple[int, int]", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:291: error: Incompatible types in assignment (expression has type "str", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:292: error: Incompatible types in assignment (expression has type "str", variable has type "Tuple[int, int, int]")
pdm/models/specifiers.py:297: error: List item 0 has incompatible type "Tuple[int, int, int]"; expected "Optional[str]"
pdm/models/specifiers.py:297: error: List item 1 has incompatible type "Tuple[int, int, int]"; expected "Optional[str]"
pdm/models/markers.py:40: error: Incompatible return value type (got "None", expected "Marker")
pdm/models/markers.py:48: error: Incompatible return value type (got "None", expected "Marker")
pdm/resolver/metaset.py:23: error: Unsupported left operand type for & ("None")
pdm/resolver/metaset.py:23: note: Both left and right operands are unions
pdm/resolver/metaset.py:35: error: Unsupported left operand type for | ("None")
pdm/resolver/metaset.py:35: note: Both left and right operands are unions
pdm/resolver/metaset.py:47: error: Unsupported left operand type for & ("None")
pdm/resolver/metaset.py:47: note: Both left and right operands are unions
pdm/models/requirements.py:146: error: Incompatible types in assignment (expression has type "Union[bool, str]", variable has type "str")
pdm/models/requirements.py:182: error: Incompatible types in assignment (expression has type "List[Any]", target has type "bool")
pdm/models/requirements.py:190: error: Incompatible types in assignment (expression has type "str", target has type "bool")
pdm/models/requirements.py:192: error: Incompatible types in assignment (expression has type "str", target has type "bool")
pdm/models/requirements.py:194: error: Incompatible types in assignment (expression has type "str", target has type "bool")
pdm/models/requirements.py:196: error: Incompatible types in assignment (expression has type "bool", variable has type "Dict[str, bool]")
pdm/models/requirements.py:200: error: Incompatible return value type (got "Tuple[Any, Dict[str, bool]]", expected "Tuple[str, Union[str, Dict[str, Union[bool, str]]]]")
pdm/models/requirements.py:271: error: Incompatible types in assignment (expression has type "Tuple[str, ...]", variable has type "Optional[str]")
pdm/models/requirements.py:281: error: Cannot determine type of 'url'
pdm/models/requirements.py:310: error: Cannot determine type of 'name'
pdm/models/requirements.py:318: error: Cannot determine type of 'extras'
pdm/models/requirements.py:384: error: Cannot determine type of 'ref'
pdm/models/requirements.py:405: error: Invalid index type "str" for "Union[str, Dict[str, Union[bool, str]]]"; expected type "Union[int, slice]"
pdm/models/requirements.py:408: error: Argument 1 to "quote" has incompatible type "Union[str, bool]"; expected "str"
pdm/models/requirements.py:408: error: Invalid index type "str" for "Union[str, Dict[str, Union[bool, str]]]"; expected type "Union[int, slice]"
pdm/models/requirements.py:416: error: Need type annotation for 'result' (hint: "result: List[<type>] = ...")
pdm/models/requirements.py:454: error: Incompatible types in assignment (expression has type "FileRequirement", variable has type "VcsRequirement")
pdm/models/requirements.py:459: error: Incompatible types in assignment (expression has type "FileRequirement", variable has type "VcsRequirement")
pdm/models/requirements.py:465: error: "VcsRequirement" has no attribute "editable"
pdm/models/candidates.py:61: error: Need type annotation for 'result' (hint: "result: List[<type>] = ...")
pdm/models/candidates.py:114: error: Need type annotation for 'sections' (hint: "sections: List[<type>] = ...")
pdm/models/candidates.py:128: error: Incompatible return value type (got "Optional[str]", expected "str")
pdm/models/candidates.py:130: error: Argument 1 of "__eq__" is incompatible with supertype "object"; supertype defines the argument type as "object"
pdm/models/candidates.py:130: note: This violates the Liskov substitution principle
pdm/models/candidates.py:130: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
pdm/models/candidates.py:130: note: It is recommended for "__eq__" to work with arbitrary objects, for example:
pdm/models/candidates.py:130: note:     def __eq__(self, other: object) -> bool:
pdm/models/candidates.py:130: note:         if not isinstance(other, Candidate):
pdm/models/candidates.py:130: note:             return NotImplemented
pdm/models/candidates.py:130: note:         return <logic to compare two Candidate instances>
pdm/models/candidates.py:155: error: Argument 2 to "pop" of "MutableMapping" has incompatible type "None"; expected "Union[List[Any], Dict[Any, Any]]"
pdm/models/candidates.py:156: error: Incompatible types in assignment (expression has type "Namespace", variable has type "None")
pdm/models/candidates.py:169: error: "None" has no attribute "metadata"
pdm/models/candidates.py:171: error: "None" has no attribute "name"
pdm/models/candidates.py:172: error: "Requirement" has no attribute "name"
pdm/models/candidates.py:174: error: "None" has no attribute "version"
pdm/models/candidates.py:207: error: Item "None" of "Optional[Any]" has no attribute "install_requires"
pdm/models/candidates.py:209: error: Item "None" of "Optional[Any]" has no attribute "extras_require"
pdm/models/candidates.py:212: error: Item "None" of "Optional[Any]" has no attribute "run_requires"
pdm/models/candidates.py:219: error: Item "None" of "Optional[Any]" has no attribute "requires_python"
pdm/models/candidates.py:238: error: Incompatible types in assignment (expression has type "str", variable has type "None")
pdm/models/candidates.py:250: error: Cannot determine type of 'root'
pdm/models/candidates.py:272: error: "IOStream" has no attribute "green"
pdm/models/candidates.py:273: error: "IOStream" has no attribute "yellow"
pdm/models/builders.py:15: error: Cannot find implementation or library stub for module named 'pep517.wrappers'
pdm/models/builders.py:20: error: Cannot find implementation or library stub for module named 'pdm.pep517.base'
pdm/models/builders.py:141: error: Cannot determine type of 'python_executable'
pdm/models/repositories.py:60: error: Need type annotation for 'requirements' (hint: "requirements: List[<type>] = ...")
pdm/models/repositories.py:71: error: Item "None" of "Optional[BaseException]" has no attribute "with_traceback"
pdm/models/repositories.py:72: error: List comprehension has incompatible type List[Requirement]; expected List[str]
pdm/models/repositories.py:79: error: "Requirement" has no attribute "extras"
pdm/models/repositories.py:80: error: Argument 1 to "append" of "list" has incompatible type "Requirement"; expected "str"
pdm/models/repositories.py:81: error: Incompatible return value type (got "Tuple[List[str], PySpecSet, str]", expected "Tuple[List[Requirement], PySpecSet, str]")
pdm/models/repositories.py:111: error: Item "None" of "Optional[Any]" has no attribute "is_wheel"
pdm/models/repositories.py:143: error: "None" has no attribute "summary"
pdm/models/repositories.py:155: error: Return value expected
pdm/models/repositories.py:159: error: "Requirement" has no attribute "specifier"
pdm/models/repositories.py:164: error: Item "None" of "Optional[Any]" has no attribute "filename"
pdm/models/repositories.py:188: error: Argument 1 to "cache_result" has incompatible type "Callable[[PyPIRepository, Candidate], Tuple[List[str], str, str]]"; expected "Callable[[BaseRepository, Candidate], Tuple[List[str], str, str]]"
pdm/models/repositories.py:197: error: Item "bool" of "Union[str, bool]" has no attribute "rstrip"
pdm/models/repositories.py:240: error: Item "bool" of "Union[str, bool]" has no attribute "rstrip"
pdm/models/repositories.py:253: error: "IOStream" has no attribute "yellow"
pdm/models/environment.py:155: error: Cannot determine type of 'root'
pdm/models/environment.py:193: error: Incompatible types in assignment (expression has type "str", variable has type "Path")
pdm/models/environment.py:195: error: Incompatible return value type (got "Path", expected "str")
pdm/models/environment.py:212: error: Argument 1 to "expand_env_vars_in_auth" has incompatible type "Union[str, bool]"; expected "str"
pdm/models/environment.py:279: error: Cannot determine type of 'root'
pdm/models/environment.py:370: error: Incompatible return value type (got "Optional[str]", expected "str")
pdm/models/environment.py:403: error: Signature of "packages_path" incompatible with supertype "Environment"
pdm/resolver/providers.py:45: error: Incompatible types in assignment (expression has type "Iterable[Candidate]", variable has type "List[Candidate]")
pdm/resolver/providers.py:91: error: Invalid index type "Optional[str]" for "Dict[str, List[Requirement]]"; expected type "str"
pdm/resolver/providers.py:118: error: "Candidate" has no attribute "_preferred"
pdm/resolver/providers.py:151: error: Argument 1 to "add" of "set" has incompatible type "Optional[str]"; expected "str"
pdm/project/core.py:128: error: Incompatible return value type (got "Optional[Any]", expected "Dict[str, Union[str, Dict[str, str]]]")
pdm/project/core.py:153: error: "IOStream" has no attribute "green"
pdm/project/core.py:184: error: "IOStream" has no attribute "green"
pdm/project/core.py:188: error: Argument 1 to "Path" has incompatible type "Optional[str]"; expected "Union[str, _PathLike[str]]"
pdm/project/core.py:189: error: Incompatible return value type (got "Optional[str]", expected "str")
pdm/project/core.py:206: error: Argument 1 to "is_venv_python" has incompatible type "str"; expected "_PathLike[Any]"
pdm/project/core.py:213: error: Item "None" of "Optional[MutableMetadata]" has no attribute "requires_python"
pdm/project/core.py:218: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:220: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:222: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:224: error: Argument 1 to "cd" has incompatible type "Path"; expected "str"
pdm/project/core.py:233: error: Incompatible return value type (got "Dict[Optional[str], Requirement]", expected "Dict[str, Requirement]")
pdm/project/core.py:246: error: Item "None" of "Optional[MutableMetadata]" has no attribute "optional_dependencies"
pdm/project/core.py:247: error: Item "None" of "Optional[MutableMetadata]" has no attribute "optional_dependencies"
pdm/project/core.py:299: error: Item "None" of "Optional[Any]" has no attribute "repository_class"
pdm/project/core.py:333: error: Argument 1 to "SpinnerReporter" has incompatible type "Optional[Halo]"; expected "Halo"
pdm/project/core.py:347: error: "IOStream" has no attribute "green"
pdm/project/core.py:352: error: "Requirement" has no attribute "name"
pdm/project/core.py:352: error: Item "None" of "Optional[MutableMetadata]" has no attribute "name"
pdm/project/core.py:354: error: Item "None" of "Optional[MutableMetadata]" has no attribute "name"
pdm/project/core.py:354: error: Item "None" of "Optional[MutableMetadata]" has no attribute "version"
pdm/project/core.py:374: error: Incompatible types in assignment (expression has type "Optional[Marker]", variable has type "None")
pdm/project/core.py:382: error: Item "None" of "Optional[MutableMetadata]" has no attribute "name"
pdm/project/core.py:382: error: Item "None" of "Optional[MutableMetadata]" has no attribute "version"
pdm/project/core.py:383: error: Item "None" of "Optional[MutableMetadata]" has no attribute "project_name"
pdm/project/core.py:384: error: Incompatible return value type (got "Dict[Optional[str], Candidate]", expected "Dict[str, Candidate]")
pdm/project/core.py:391: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:392: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:393: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:394: error: Item "None" of "Optional[MutableMetadata]" has no attribute "get"
pdm/project/core.py:439: error: "List[str]" has no attribute "_value"
pdm/project/core.py:440: error: "List[str]" has no attribute "_value"
pdm/project/core.py:443: error: "List[str]" has no attribute "_value"
pdm/project/core.py:446: error: "List[str]" has no attribute "multiline"
pdm/project/core.py:455: error: "IOStream" has no attribute "green"
pdm/project/core.py:479: error: Argument 1 to "Path" has incompatible type "Optional[Any]"; expected "Union[str, _PathLike[str]]"
pdm/resolver/core.py:39: error: No return value expected
pdm/resolver/core.py:51: error: "_identify_parent" does not return a value
pdm/resolver/core.py:58: error: "_identify_parent" does not return a value
pdm/resolver/core.py:61: error: Unsupported left operand type for | ("None")
pdm/resolver/core.py:75: error: Incompatible types in assignment (expression has type "Set[<nothing>]", target has type "Set[str]")
pdm/resolver/core.py:81: error: "_identify_parent" does not return a value
pdm/resolver/core.py:105: error: "_identify_parent" does not return a value
pdm/resolver/core.py:109: error: Argument 3 to "_build_metaset" has incompatible type "Set[str]"; expected "Set[Optional[str]]"
pdm/resolver/core.py:126: error: "_identify_parent" does not return a value
pdm/installers/installers.py:31: error: "IOStream" has no attribute "yellow"
pdm/cli/options.py:157: error: "IOStream" has no attribute "red"
pdm/installers/synchronizers.py:161: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:161: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:162: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:169: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:170: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:171: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:176: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:177: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:178: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:190: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:190: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:196: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:197: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:202: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:203: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:212: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:213: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:214: error: "IOStream" has no attribute "red"
pdm/installers/synchronizers.py:234: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:235: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:241: error: "IOStream" has no attribute "green"
pdm/installers/synchronizers.py:242: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:257: error: "IOStream" has no attribute "yellow"
pdm/installers/synchronizers.py:283: error: Item "None" of "Optional[MutableMetadata]" has no attribute "name"
pdm/installers/synchronizers.py:284: error: Item "None" of "Optional[MutableMetadata]" has no attribute "project_name"
pdm/installers/synchronizers.py:329: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:216: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:218: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:222: error: "IOStream" has no attribute "yellow"
pdm/cli/utils.py:225: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:227: error: "IOStream" has no attribute "green"
pdm/cli/utils.py:260: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:262: error: "IOStream" has no attribute "yellow"
pdm/cli/utils.py:265: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:267: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:276: error: "IOStream" has no attribute "green"
pdm/cli/utils.py:280: error: Need type annotation for 'parents' (hint: "parents: List[<type>] = ...")
pdm/cli/utils.py:280: error: "object" has no attribute "name"
pdm/cli/utils.py:280: error: <nothing> has no attribute "name"
pdm/cli/utils.py:305: error: Item "None" of "Optional[MutableMetadata]" has no attribute "project_name"
pdm/cli/utils.py:375: error: "Requirement" has no attribute "specifier"
pdm/cli/utils.py:379: error: "Requirement" has no attribute "specifier"
pdm/cli/utils.py:387: error: "IOStream" has no attribute "green"
pdm/cli/utils.py:403: error: Module has no attribute "check_fingerprint"
pdm/cli/utils.py:430: error: "IOStream" has no attribute "red"
pdm/cli/utils.py:437: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:68: error: "None" has no attribute "resolver_class"
pdm/cli/actions.py:82: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:122: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:130: error: "None" has no attribute "synchronizer_class"
pdm/cli/actions.py:170: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:173: error: Argument 1 to "update" of "dict" has incompatible type "Dict[Optional[str], Requirement]"; expected "Mapping[str, Requirement]"
pdm/cli/actions.py:175: error: Argument 3 to "do_lock" has incompatible type "Set[Optional[str]]"; expected "Optional[Iterable[str]]"
pdm/cli/actions.py:178: error: Argument 1 to "save_version_specifiers" has incompatible type "Dict[Optional[str], Requirement]"; expected "Dict[str, Requirement]"
pdm/cli/actions.py:179: error: Argument 1 to "add_dependencies" of "Project" has incompatible type "Dict[Optional[str], Requirement]"; expected "Dict[str, Requirement]"
pdm/cli/actions.py:247: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:251: error: "Requirement" has no attribute "specifier"
pdm/cli/actions.py:256: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:296: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:306: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:339: error: Incompatible types in assignment (expression has type "str", variable has type "bool")
pdm/cli/actions.py:341: error: Incompatible types in assignment (expression has type "str", variable has type "bool")
pdm/cli/actions.py:342: error: Argument 1 to "echo" of "IOStream" has incompatible type "bool"; expected "str"
pdm/cli/actions.py:345: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:348: error: Argument 1 to "display_columns" of "IOStream" has incompatible type "List[Tuple[Any, str]]"; expected "List[List[str]]"
pdm/cli/actions.py:412: error: Unsupported target for indexed assignment ("Optional[Any]")
pdm/cli/actions.py:413: error: Unsupported target for indexed assignment ("Optional[Any]")
pdm/cli/actions.py:426: error: Argument 1 to "find_python_in_path" has incompatible type "str"; expected "_PathLike[Any]"
pdm/cli/actions.py:428: error: Incompatible types in assignment (expression has type "Optional[str]", variable has type "str")
pdm/cli/actions.py:445: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:465: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:473: error: "IOStream" has no attribute "cyan"
pdm/cli/actions.py:489: error: "IOStream" has no attribute "cyan"
pdm/cli/actions.py:489: error: "None" has no attribute "version"
pdm/cli/actions.py:491: error: "IOStream" has no attribute "cyan"
pdm/cli/actions.py:495: error: "IOStream" has no attribute "cyan"
pdm/cli/actions.py:497: error: Argument 1 to "display_columns" of "IOStream" has incompatible type "List[Tuple[Any, Any]]"; expected "List[List[str]]"
pdm/cli/actions.py:523: error: Module has no attribute "check_fingerprint"
pdm/cli/actions.py:532: error: Module has no attribute "convert"
pdm/cli/actions.py:562: error: "IOStream" has no attribute "cyan"
pdm/cli/actions.py:565: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:569: error: "IOStream" has no attribute "yellow"
pdm/cli/actions.py:580: error: Argument 2 to "do_import" has incompatible type "Path"; expected "str"
pdm/cli/actions.py:613: error: Module has no attribute "check_fingerprint"
pdm/cli/actions.py:619: error: "IOStream" has no attribute "yellow"
pdm/cli/actions.py:622: error: Argument 2 to "do_import" has incompatible type "Path"; expected "str"
pdm/cli/actions.py:624: error: "IOStream" has no attribute "green"
pdm/cli/actions.py:625: error: "IOStream" has no attribute "yellow"
pdm/core.py:27: error: Cannot find implementation or library stub for module named 'importlib_metadata'
pdm/core.py:27: error: Name 'importlib_metadata' already defined (by an import)
pdm/core.py:29: error: Module has no attribute "__path__"
pdm/core.py:144: error: "Type[BaseCommand]" has no attribute "project_class"
pdm/cli/commands/show.py:18: error: Item "str" of "Union[str, Any]" has no attribute "is_prerelease"
pdm/cli/commands/show.py:43: error: "IOStream" has no attribute "yellow"
pdm/cli/commands/show.py:50: error: Item "None" of "Optional[Any]" has no attribute "_legacy"
pdm/cli/commands/show.py:51: error: Item "None" of "Optional[Any]" has no attribute "_legacy"
pdm/cli/commands/show.py:53: error: Item "None" of "Optional[Any]" has no attribute "_data"
pdm/cli/commands/show.py:59: error: Argument 1 to "list" has incompatible type "Iterator[Tuple[str, str]]"; expected "Iterable[List[str]]"
pdm/cli/commands/search.py:33: error: Incompatible types in assignment (expression has type "List[str]", variable has type "str")
pdm/cli/commands/search.py:38: error: "IOStream" has no attribute "green"
pdm/cli/commands/search.py:39: error: "IOStream" has no attribute "yellow"
pdm/cli/commands/run.py:46: error: List item 1 has incompatible type "Optional[str]"; expected "str"
pdm/cli/commands/run.py:57: error: Cannot find implementation or library stub for module named 'dotenv'
pdm/cli/commands/run.py:57: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
pdm/cli/commands/run.py:59: error: "IOStream" has no attribute "green"
pdm/cli/commands/run.py:66: error: Value of type variable "AnyStr" of "expandvars" cannot be "Union[List[str], str]"
pdm/cli/commands/run.py:68: error: Unpacking a string is disallowed
pdm/cli/commands/run.py:73: error: "IOStream" has no attribute "green"
pdm/cli/commands/run.py:122: error: Incompatible types in assignment (expression has type "str", variable has type "List[str]")
pdm/cli/commands/run.py:140: error: List item 0 has incompatible type "Union[str, Dict[str, str]]"; expected "Mapping[str, str]"
pdm/cli/commands/run.py:144: error: "IOStream" has no attribute "green"
pdm/cli/commands/run.py:156: error: "IOStream" has no attribute "green"
pdm/cli/commands/run.py:157: error: Argument 1 to "display_columns" of "IOStream" has incompatible type "List[Tuple[Any, Any, Any, Any]]"; expected "List[List[str]]"
pdm/cli/commands/run.py:164: error: Argument 4 to "_run_script" of "Command" has incompatible type "Union[str, Dict[str, str]]"; expected "Dict[str, Union[str, Dict[str, str]]]"
pdm/cli/commands/run.py:166: error: Argument after ** must be a mapping
pdm/cli/commands/install.py:27: error: Module has no attribute "_compat"
pdm/cli/commands/init.py:17: error: "Command" has no attribute "project_class"
pdm/cli/commands/init.py:23: error: "IOStream" has no attribute "cyan"
pdm/cli/commands/init.py:28: error: "IOStream" has no attribute "cyan"
pdm/cli/commands/import_cmd.py:32: error: "Command" has no attribute "project_class"
pdm/cli/commands/export.py:42: error: Need type annotation for 'candidates' (hint: "candidates: List[<type>] = ...")
pdm/cli/commands/export.py:50: error: Incompatible types in assignment (expression has type "Dict[str, Candidate]", variable has type "Dict[str, Requirement]")
pdm/cli/commands/export.py:51: error: Item "None" of "Optional[MutableMetadata]" has no attribute "name"
pdm/cli/commands/export.py:63: error: Module has no attribute "export"
pdm/cli/commands/config.py:48: error: "IOStream" has no attribute "yellow"
pdm/cli/commands/config.py:53: error: "IOStream" has no attribute "cyan"
pdm/cli/commands/config.py:62: error: "IOStream" has no attribute "yellow"
pdm/cli/commands/config.py:67: error: "IOStream" has no attribute "cyan"
pdm/cli/commands/completion.py:11: error: Need type annotation for 'arguments' (hint: "arguments: List[<type>] = ...")
pdm/cli/commands/completion.py:25: error: "None" has no attribute "parser"
Found 381 errors in 35 files (checked 86 source files)

@ghost
Copy link

ghost commented Mar 29, 2021

@danieleades
Hi, I appreciate your contributing of typing.

I suggest ​this project only enables ignore-missing-imports, but I think below are good as well. What do you think?

[mypy]
disallow_untyped_defs=True
disallow_untyped_calls=True
ignore_missing_imports=True

And if ci has mypy after solving all errors, it would be great.
Shall I have some tasks if you can split up?

@danieleades
Copy link
Contributor Author

@danieleades
Hi, I appreciate your contributing of typing.

I suggest ​this project only enables ignore-missing-imports, but I think below are good as well. What do you think?

[mypy]
disallow_untyped_defs=True
disallow_untyped_calls=True
ignore_missing_imports=True

And if ci has mypy after solving all errors, it would be great.
Shall I have some tasks if you can split up?

that seems like a reasonable mypy config. i'm using something similar locally while i'm messing about. I suggest perhaps you should open a pull request to add the config file and dependencies to the repo?

As for breaking down the separate tasks, so far i've just been tackling one file at a time, starting with the ones that generate the most errors.

Personally, i'm not going to be able to make a lot more progress without input from @frostming. A lot of the remaining type errors stem from using objects that might be None, which in turn comes from using a lot of loosely-typed data structures. Will require some reasonably deep knowledge of the code to refactor a lot of these. You might have more luck!

@ghost
Copy link

ghost commented Mar 29, 2021

Sure, I got it. I'll check them later.

Almost all codes are covered by pytest thanks to the author, so we can check sys.setprofile to what type is required for all functions, I think.

I'll make PR while checking your PR.

@danieleades
Copy link
Contributor Author

This isn't really working. @frostming is it possible for you to use mypy to lint new code as you add it? Is that something you'd be interested in?

You're adding code at a very fast rate, and despite addressing hundreds of type errors, there's now more errors than when I started...

@pohlt
Copy link
Contributor

pohlt commented Apr 30, 2021

First of all, thanks a lot @danieleades for looking into this topic. "There is no glory in prevention" and the same is true for linting and type checking, I'm afraid to say. 😉
Still, I think that a lot of potential pdm users and contributors would very much appreciate a sound software base including black, isort, flake8, and mypy (at least I do).

Of course, pdm is your baby, @frostming, and working on new features is so much more attractive than introducing mypy for an extensive code base, but the long-term benefits of using mypy (or sth similar) are substantial and well worth the effort, IMHO.

That's just my two cents worth.

@frostming
Copy link
Collaborator

I never disregard type hints, I myself also improved the types and reduced the error number by ~100. Everyone can contribute to improving this and I am glad to review it.

This isn't really working.

Don't urge on that, many errors were introduced by a patch that applied types from an automation tool(pyannotate). Keep on the good work and we will finally get the green flag to add mypy in pre-commit and CI!

@danieleades
Copy link
Contributor Author

Apologies all! Planning to do a little more on this when I can. In the middle of a home renovation, so I'm short on free time right now!

@danieleades
Copy link
Contributor Author

right, i've got a plan. i've added a mypy config and pre-commit hook in #427

the pre-commit hook has a small whitelist of files. over time, as type errors are stripped from files they can be added to the whitelist. This prevents type errors from being re-introduced to existing files that have been 'cleared'. Any new files should be added to this whitelist in the pull request in which they're created. Sound ok?

@frostming
Copy link
Collaborator

Here is the good news: all type errors in the codebase are cleared #517

Thanks all

@danieleades
Copy link
Contributor Author

Amazing effort. Well done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants