In tkinter, `widget['foo'] = bar` and `widget.config(foo=bar)` do the same thing, but they will now type-check differently: the `widget['foo'] = bar` syntax allows 'foo' to be any string (e.g. a variable, not necessarily a Literal) and bar to be any object, while `widget.config(foo=bar)` checks the existence of the option and the type of bar. Similarly, cget takes a Literal argument but __getitem__ takes a string.
Testing script can still be found at c42a72c53e
CDLL.__getattr__ and __getitem__ return function pointers that have a __name__ attribute set, so "CDLL(lib).fun.__name__" is valid code but currently not covered.
PEP 484 indicates that all type annotations within a stub file are supposed to be considered forward references even if they are not quoted. This means a type checker needs to use scope-based symbol resolution without regard for code flow order. Lookups will find same-named symbols within the same scope even if they are declared after the type annotation. This change fixes a couple of cases where this occurs and confuses pyright.
Co-authored-by: Eric Traut <erictr@microsoft.com>
* Replaced parameter name "self" with "cls" for a few class methods. Pyright emits a warning if a class method doesn't follow the PEP 8 standard where the first parameter is named "cls" for a class method. This change eliminates these warnings.
* Missed a file.
Co-authored-by: Eric Traut <erictr@microsoft.com>
* PEP 484 says that type checkers should assume that all types used in a stub should use forward declarations even though they are not quoted. This stub is using the symbol "type" within the context of a class scope. The "type" symbol is declared within this scope, so pyright assumes that the forward declaration should be used. The solution is to define a symbol with a different name in the outer scope to avoid the name conflict.
* Fixed import sort order.
Co-authored-by: Eric Traut <erictr@microsoft.com>
* Pyright detects and reports cases where a multi-part module name is accessed but is not explicitly imported. These are dangerous because they rely on import resolution ordering within a program, which can easily change. This change eliminates errors detected by pyright.
* Fixed regression caught by CI test.
* Fixed black formatting issues.
Co-authored-by: Eric Traut <erictr@microsoft.com>
This makes mypy think that conditions like
parameter.kind is Parameter.POSITIONAL_OR_KEYWORD
are always false, which triggers `unreachable` warnings, among other
problems.
* Enable some branches for Python2 pathlib2
* Define an alias _PathLike, instead of using multiple branches
* Drop a Python 3.4 branch (the Python 2 branch is identical to
the 3.5+ branch)
* Move Path.__new__ to the top
Add support for the following syslog facilities:
- LOG_NTP
- LOG_SECURITY
- LOG_CONSOLE
- LOG_SOLCRON
In addition, reorder the entries to match the CPython implementation to
make it easier to read.
typing.Mapping is not a protocol, which has caused problems in the past.
(E.g. python/typeshed#3569, see also python/typeshed#3576.) This
introduces a few narrow protocols to _typeshed.pyi that can be used in
place of Mapping.
Not all uses of Mapping can be replaced. For example, cgi.FieldStorage
explictly checks whether the supplied headers argument is a Mapping
instance.