Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chcg committed Apr 15, 2022
1 parent 09adfc3 commit 61e635e
Show file tree
Hide file tree
Showing 67 changed files with 139 additions and 105 deletions.
2 changes: 1 addition & 1 deletion PythonLib/full/asynchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

from warnings import warn
warn(
'The asynchat module is deprecated. '
'The asynchat module is deprecated and will be removed in Python 3.12. '
'The recommended replacement is asyncio',
DeprecationWarning,
stacklevel=2)
Expand Down
16 changes: 10 additions & 6 deletions PythonLib/full/asyncio/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from . import exceptions
from . import mixins
from . import tasks


class _ContextManagerMixin:
Expand Down Expand Up @@ -350,6 +351,7 @@ def __init__(self, value=1, *, loop=mixins._marker):
raise ValueError("Semaphore initial value must be >= 0")
self._value = value
self._waiters = collections.deque()
self._wakeup_scheduled = False

def __repr__(self):
res = super().__repr__()
Expand All @@ -363,6 +365,7 @@ def _wake_up_next(self):
waiter = self._waiters.popleft()
if not waiter.done():
waiter.set_result(None)
self._wakeup_scheduled = True
return

def locked(self):
Expand All @@ -378,16 +381,17 @@ async def acquire(self):
called release() to make it larger than 0, and then return
True.
"""
while self._value <= 0:
# _wakeup_scheduled is set if *another* task is scheduled to wakeup
# but its acquire() is not resumed yet
while self._wakeup_scheduled or self._value <= 0:
fut = self._get_loop().create_future()
self._waiters.append(fut)
try:
await fut
except:
# See the similar code in Queue.get.
fut.cancel()
if self._value > 0 and not fut.cancelled():
self._wake_up_next()
# reset _wakeup_scheduled *after* waiting for a future
self._wakeup_scheduled = False
except exceptions.CancelledError:
self._wake_up_next()
raise
self._value -= 1
return True
Expand Down
2 changes: 1 addition & 1 deletion PythonLib/full/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
errorcode

warnings.warn(
'The asyncore module is deprecated. '
'The asyncore module is deprecated and will be removed in Python 3.12. '
'The recommended replacement is asyncio',
DeprecationWarning,
stacklevel=2)
Expand Down
3 changes: 3 additions & 0 deletions PythonLib/full/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ def __init__(self, test, optionflags=0, setUp=None, tearDown=None,
unittest.TestCase.__init__(self)
self._dt_optionflags = optionflags
self._dt_checker = checker
self._dt_globs = test.globs.copy()
self._dt_test = test
self._dt_setUp = setUp
self._dt_tearDown = tearDown
Expand All @@ -2187,7 +2188,9 @@ def tearDown(self):
if self._dt_tearDown is not None:
self._dt_tearDown(test)

# restore the original globs
test.globs.clear()
test.globs.update(self._dt_globs)

def runTest(self):
test = self._dt_test
Expand Down
22 changes: 13 additions & 9 deletions PythonLib/full/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class or function within a module or module in a package. If the
import sysconfig
import time
import tokenize
import types
import urllib.parse
import warnings
from collections import deque
Expand All @@ -90,21 +91,24 @@ def pathdirs():
normdirs.append(normdir)
return dirs

def _isclass(object):
return inspect.isclass(object) and not isinstance(object, types.GenericAlias)

def _findclass(func):
cls = sys.modules.get(func.__module__)
if cls is None:
return None
for name in func.__qualname__.split('.')[:-1]:
cls = getattr(cls, name)
if not inspect.isclass(cls):
if not _isclass(cls):
return None
return cls

def _finddoc(obj):
if inspect.ismethod(obj):
name = obj.__func__.__name__
self = obj.__self__
if (inspect.isclass(self) and
if (_isclass(self) and
getattr(getattr(self, name, None), '__func__') is obj.__func__):
# classmethod
cls = self
Expand All @@ -118,7 +122,7 @@ def _finddoc(obj):
elif inspect.isbuiltin(obj):
name = obj.__name__
self = obj.__self__
if (inspect.isclass(self) and
if (_isclass(self) and
self.__qualname__ + '.' + name == obj.__qualname__):
# classmethod
cls = self
Expand Down Expand Up @@ -205,7 +209,7 @@ def classname(object, modname):

def isdata(object):
"""Check if an object is of a type that probably means it's data."""
return not (inspect.ismodule(object) or inspect.isclass(object) or
return not (inspect.ismodule(object) or _isclass(object) or
inspect.isroutine(object) or inspect.isframe(object) or
inspect.istraceback(object) or inspect.iscode(object))

Expand Down Expand Up @@ -470,7 +474,7 @@ def document(self, object, name=None, *args):
# by lacking a __name__ attribute) and an instance.
try:
if inspect.ismodule(object): return self.docmodule(*args)
if inspect.isclass(object): return self.docclass(*args)
if _isclass(object): return self.docclass(*args)
if inspect.isroutine(object): return self.docroutine(*args)
except AttributeError:
pass
Expand Down Expand Up @@ -775,7 +779,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
modules = inspect.getmembers(object, inspect.ismodule)

classes, cdict = [], {}
for key, value in inspect.getmembers(object, inspect.isclass):
for key, value in inspect.getmembers(object, _isclass):
# if __all__ exists, believe it. Otherwise use old heuristic.
if (all is not None or
(inspect.getmodule(value) or object) is object):
Expand Down Expand Up @@ -1217,7 +1221,7 @@ def docmodule(self, object, name=None, mod=None):
result = result + self.section('DESCRIPTION', desc)

classes = []
for key, value in inspect.getmembers(object, inspect.isclass):
for key, value in inspect.getmembers(object, _isclass):
# if __all__ exists, believe it. Otherwise use old heuristic.
if (all is not None
or (inspect.getmodule(value) or object) is object):
Expand Down Expand Up @@ -1699,7 +1703,7 @@ def describe(thing):
return 'member descriptor %s.%s.%s' % (
thing.__objclass__.__module__, thing.__objclass__.__name__,
thing.__name__)
if inspect.isclass(thing):
if _isclass(thing):
return 'class ' + thing.__name__
if inspect.isfunction(thing):
return 'function ' + thing.__name__
Expand Down Expand Up @@ -1760,7 +1764,7 @@ def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
desc += ' in module ' + module.__name__

if not (inspect.ismodule(object) or
inspect.isclass(object) or
_isclass(object) or
inspect.isroutine(object) or
inspect.isdatadescriptor(object) or
_getdoc(object)):
Expand Down
78 changes: 41 additions & 37 deletions PythonLib/full/pydoc_data/topics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Autogenerated by Sphinx on Wed Mar 16 11:26:55 2022
# Autogenerated by Sphinx on Wed Mar 23 20:11:40 2022
topics = {'assert': 'The "assert" statement\n'
'**********************\n'
'\n'
Expand Down Expand Up @@ -2418,11 +2418,11 @@
'resulting\n'
'object is “compatible” with the exception. An object is '
'compatible\n'
'with an exception if it is the class or a base class of the '
'exception\n'
'object, or a tuple containing an item that is the class or a '
'with an exception if the object is the class or a *non-virtual '
'base\n'
'class of the exception object.\n'
'class* of the exception object, or a tuple containing an item '
'that is\n'
'the class or a non-virtual base class of the exception object.\n'
'\n'
'If no except clause matches the exception, the search for an '
'exception\n'
Expand Down Expand Up @@ -4399,15 +4399,17 @@
'on members\n'
' of hashed collections including "set", "frozenset", and '
'"dict".\n'
' "__hash__()" should return an integer. The only required '
'property\n'
' is that objects which compare equal have the same hash '
'value; it is\n'
' advised to mix together the hash values of the '
'components of the\n'
' object that also play a part in comparison of objects by '
'packing\n'
' them into a tuple and hashing the tuple. Example:\n'
' The "__hash__()" method should return an integer. The '
'only required\n'
' property is that objects which compare equal have the '
'same hash\n'
' value; it is advised to mix together the hash values of '
'the\n'
' components of the object that also play a part in '
'comparison of\n'
' objects by packing them into a tuple and hashing the '
'tuple.\n'
' Example:\n'
'\n'
' def __hash__(self):\n'
' return hash((self.name, self.nick, self.color))\n'
Expand Down Expand Up @@ -5391,11 +5393,11 @@
'clause is\n'
'selected depending on the class of the instance: it must '
'reference the\n'
'class of the instance or a base class thereof. The instance '
'can be\n'
'received by the handler and can carry additional information '
'about the\n'
'exceptional condition.\n'
'class of the instance or a *non-virtual base class* thereof. '
'The\n'
'instance can be received by the handler and can carry '
'additional\n'
'information about the exceptional condition.\n'
'\n'
'Note:\n'
'\n'
Expand Down Expand Up @@ -5730,11 +5732,11 @@
'clause is\n'
'selected depending on the class of the instance: it must '
'reference the\n'
'class of the instance or a base class thereof. The instance '
'can be\n'
'received by the handler and can carry additional information '
'about the\n'
'exceptional condition.\n'
'class of the instance or a *non-virtual base class* thereof. '
'The\n'
'instance can be received by the handler and can carry '
'additional\n'
'information about the exceptional condition.\n'
'\n'
'Note:\n'
'\n'
Expand Down Expand Up @@ -9303,15 +9305,17 @@
'on members\n'
' of hashed collections including "set", "frozenset", and '
'"dict".\n'
' "__hash__()" should return an integer. The only required '
'property\n'
' is that objects which compare equal have the same hash '
'value; it is\n'
' advised to mix together the hash values of the components '
'of the\n'
' object that also play a part in comparison of objects by '
'packing\n'
' them into a tuple and hashing the tuple. Example:\n'
' The "__hash__()" method should return an integer. The '
'only required\n'
' property is that objects which compare equal have the '
'same hash\n'
' value; it is advised to mix together the hash values of '
'the\n'
' components of the object that also play a part in '
'comparison of\n'
' objects by packing them into a tuple and hashing the '
'tuple.\n'
' Example:\n'
'\n'
' def __hash__(self):\n'
' return hash((self.name, self.nick, self.color))\n'
Expand Down Expand Up @@ -12428,10 +12432,10 @@
'exception. For an except clause with an expression, that expression\n'
'is evaluated, and the clause matches the exception if the resulting\n'
'object is “compatible” with the exception. An object is compatible\n'
'with an exception if it is the class or a base class of the '
'exception\n'
'object, or a tuple containing an item that is the class or a base\n'
'class of the exception object.\n'
'with an exception if the object is the class or a *non-virtual base\n'
'class* of the exception object, or a tuple containing an item that '
'is\n'
'the class or a non-virtual base class of the exception object.\n'
'\n'
'If no except clause matches the exception, the search for an '
'exception\n'
Expand Down
3 changes: 2 additions & 1 deletion PythonLib/full/smtpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
]

warn(
'The smtpd module is deprecated and unmaintained. Please see aiosmtpd '
'The smtpd module is deprecated and unmaintained and will be removed '
'in Python 3.12. Please see aiosmtpd '
'(https://aiosmtpd.readthedocs.io/) for the recommended replacement.',
DeprecationWarning,
stacklevel=2)
Expand Down
4 changes: 3 additions & 1 deletion PythonLib/full/sre_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,11 @@ def _parse(source, state, verbose, nested, first=False):
if not first or subpattern:
import warnings
warnings.warn(
'Flags not at the start of the expression %r%s' % (
'Flags not at the start of the expression %r%s'
' but at position %d' % (
source.string[:20], # truncate long regexes
' (truncated)' if len(source.string) > 20 else '',
start,
),
DeprecationWarning, stacklevel=nested + 6
)
Expand Down
2 changes: 1 addition & 1 deletion PythonLib/full/unittest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _convert_name(name):
name = rel_path
# on Windows both '\' and '/' are used as path
# separators. Better to replace both than rely on os.path.sep
return name[:-3].replace('\\', '.').replace('/', '.')
return os.path.normpath(name)[:-3].replace('\\', '.').replace('/', '.')
return name

def _convert_names(names):
Expand Down
Loading

0 comments on commit 61e635e

Please sign in to comment.