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

Favoring builtins over __builtins__ and removing redundant usages #2362

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions AutoDuck/py2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ def ad_escape(s):
return re.sub(r"([^<]*)<([^>]*)>", r"\g<1>\\<\g<2>\\>", s)


Print = __builtins__.__dict__["print"]


class DocInfo:
def __init__(self, name, ob):
self.name = name
Expand Down Expand Up @@ -112,30 +109,30 @@ def build_module(fp, mod_name):
elif name.upper() == name and isinstance(ob, (int, str)):
constants.append((name, ob))
info = BuildInfo(mod_name, mod)
Print(f"// @module {mod_name}|{format_desc(info.desc)}", file=fp)
print(f"// @module {mod_name}|{format_desc(info.desc)}", file=fp)
functions = [f for f in functions if should_build_function(f)]
for ob in functions:
Print(f"// @pymeth {ob.name}|{ob.short_desc}", file=fp)
print(f"// @pymeth {ob.name}|{ob.short_desc}", file=fp)
for ob in classes:
# only classes with docstrings get printed.
if not ob.ob.__doc__:
continue
ob_name = mod_name + "." + ob.name
Print(f"// @pyclass {ob.name}|{ob.short_desc}", file=fp)
print(f"// @pyclass {ob.name}|{ob.short_desc}", file=fp)
for ob in functions:
Print(
print(
f"// @pymethod |{mod_name}|{ob.name}|{format_desc(ob.desc)}",
file=fp,
)
for ai in BuildArgInfos(ob.ob):
Print(f"// @pyparm |{ai.name}|{ai.default}|{ai.short_desc}", file=fp)
print(f"// @pyparm |{ai.name}|{ai.default}|{ai.short_desc}", file=fp)

for ob in classes:
# only classes with docstrings get printed.
if not ob.ob.__doc__:
continue
ob_name = mod_name + "." + ob.name
Print(f"// @object {ob_name}|{format_desc(ob.desc)}", file=fp)
print(f"// @object {ob_name}|{format_desc(ob.desc)}", file=fp)
func_infos = []
# We need to iter the keys then to a getattr() so the funky descriptor
# things work.
Expand All @@ -146,20 +143,20 @@ def build_module(fp, mod_name):
if should_build_function(info):
func_infos.append(info)
for fi in func_infos:
Print(f"// @pymeth {fi.name}|{fi.short_desc}", file=fp)
print(f"// @pymeth {fi.name}|{fi.short_desc}", file=fp)
for fi in func_infos:
Print(
print(
f"// @pymethod |{ob_name}|{fi.name}|{format_desc(fi.desc)}",
file=fp,
)
if hasattr(fi.ob, "im_self") and fi.ob.im_self is ob.ob:
Print("// @comm This is a @classmethod.", file=fp)
Print(
print("// @comm This is a @classmethod.", file=fp)
print(
f"// @pymethod |{ob_name}|{fi.name}|{format_desc(fi.desc)}",
file=fp,
)
for ai in BuildArgInfos(fi.ob):
Print(
print(
f"// @pyparm |{ai.name}|{ai.default}|{ai.short_desc}",
file=fp,
)
Expand All @@ -168,11 +165,11 @@ def build_module(fp, mod_name):
desc = f"{name} = {val!r}"
if isinstance(val, int):
desc += f" (0x{val:x})"
Print(f"// @const {mod_name}|{name}|{desc}", file=fp)
print(f"// @const {mod_name}|{name}|{desc}", file=fp)


def main(fp, args):
Print("// @doc", file=fp)
print("// @doc", file=fp)
for arg in args:
build_module(sys.stdout, arg)

Expand Down
8 changes: 4 additions & 4 deletions Pythonwin/pywin/framework/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# The application is responsible for managing the main frame window.
#
# We also grab the FileOpen command, to invoke our Python editor
" The PythonWin application code. Manages most aspects of MDI, etc "
"The PythonWin application code. Manages most aspects of MDI, etc"

from __future__ import annotations

import builtins
import os
import sys
import traceback
Expand Down Expand Up @@ -392,9 +394,7 @@ def Win32Input(prompt=None):


def HookInput():
import code

sys.modules["builtins"].input = Win32Input
builtins.input = Win32Input


def HaveGoodGUI():
Expand Down
3 changes: 2 additions & 1 deletion com/win32com/client/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# OleItem, DispatchItem, MapEntry, BuildCallList() is used by makepy

import builtins
import datetime
import string
from itertools import chain
Expand Down Expand Up @@ -657,7 +658,7 @@ def MakePublicAttributeName(className, is_global=False):
if ret == className:
ret = ret.upper()
return ret
elif is_global and hasattr(__builtins__, className):
elif is_global and hasattr(builtins, className):
# builtins may be mixed case. If capitalizing it doesn't change it,
# force to all uppercase (eg, "None", "True" become "NONE", "TRUE"
ret = className.capitalize()
Expand Down
5 changes: 2 additions & 3 deletions com/win32com/test/testPippo.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ def testNumpyArrays(self):
self._testArray(numpy.array([-3.14, -2, -0.1, 0.0, 1.1, 2.5, 3]))

def testByteArrays(self):
if "bytes" in dir(__builtins__):
self._testArray(b"abcdef")
self._testArray(bytearray(b"abcdef"))
self._testArray(b"abcdef")
self._testArray(bytearray(b"abcdef"))

def _testArray(self, inArray):
outArray = self.object.Method3(inArray)
Expand Down
Loading