* add typing.ContextManager for 3.6+ only
This fixes the easier part of #655.
Would it make sense to add a generic typing.ContextManager that exists in any Python version?
* update comment
* fix argument types for ContextManager.__exit__
* add AsyncContextManager
* add @asynccontextmanager
* typing.ContextManager now always exists
* back out async-related changes
Will submit those in a separate PR later
* fix import order
* AbstractContextManager only exists in 3.6+
* AbstractContextManager -> ContextManager
The previous change was still right. Unique among `poplib` functions, `uidl()` returns a long response when called without arguments, but just a bytes string when called with a `which` argument.
* Fix incorrect usage of AnyStr
- sqlite3 was using Union[bytes, AnyStr], which doesn't make sense
- The urllib functions I changed accept either bytes or str for their "safe"
argument
- Also added supports for PathLike to pstats
- Remove some unused imports of AnyStr
* pstats: python 2 accepts unicode
* Change Uses of List[] to Sequence[] in argument positions.
One of these (parse_args()) broke in real-world code, because the
expected type was List[Union[str, bytes]] but the actual type was
List[str] (because List is invariant). That is ridiculous, so I
changed the accepted type to Sequence[_Text] which is covariant. Then
I found a few other methods/functions that probably should also be
changed to Sequence, but I'm less certain of those. I'm not at all
sure about the instance/class attributes, so I left those alone
(though I suspect those might also have to switch).
* Fixes suggested by code review
- Changed Sequence[Option] to Iterable[Option] everywhere
- Changed _process_args to plain List
* Partial lib2to3 stubs
* Use typing.Text instead of str
* Add a _Path shortcut for managing PathLike
* Respond to review, pgen2/driver
* Respond to review, pgen2/grammar
* Respond to review, pgen2/parse
* Respond to review, pgen2/pgen
* Respond to review, pgen2/token
* Respond to review, pgen2/tokenize
* Respond to review, pytree
* Move to 2and3
* Make pytype happy
* Respond to review nits
* Move _RawNode, _Convert to pytree and make the latter return None
* Make concrete Symbols subclasses for python and pattern
* Add missing Callable import
mypy could not recognize the case when we use contextmanager as a
decorator, which has been supported since Python 3.2.
In the following code snippet,
from contextlib import contextmanager
@contextmanager
def foo(arg1):
try:
print(arg1)
print('1')
yield
finally:
print('2')
@foo('0')
def foo2():
print('3')
foo2()
we get mypy error as follows,
error: ContextManager[Any] not callable
The suggested changes can fix this error and properly reflect the
updated contextmanager usage pattern.
* Simplify and add missing types for copy module.
Error and error were missing. I also removed the internal arg memo.
* Move copy module into 2and3
* Bring back internal kwargs
None is the default value for these two arguments to logging.Logger._log (which
most other stuff in logging delegates to).
I was getting errors in my codebase because mypy now distinguishes between Any
and Optional[Any].