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

attempt to use str() to get object name #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

divinity76
Copy link

@divinity76 divinity76 commented May 12, 2022

lots of things possibly wrong with this

  • i don't know if this works on python2.7
  • i don't know if this is a good fix
  • i don't know what this might break
  • i did not run it through any testsuite (does a testsuite exist? if it does, i am unaware)
  • i don't know if str(object) even can throw (i just assumed it was a possibility and added fallback to the old method if it does throw)

however, previously this

import ctypes
import ctypes.wintypes
from var_dump import var_dump

foo = ctypes.wintypes.ULARGE_INTEGER(123)
print(foo)
var_dump(foo)

would produce

c_ulonglong(123)
#0 object(c_ulonglong) (0)

and print() actually did a better job than var_dump() here,
but now it produce:

c_ulonglong(123)
#0 object(c_ulonglong(123)) (0)

doing at least as good a job as print :)
this also fixes ctypes.wintypes.HANDLE which has the same problem as ctypes.wintypes.ULARGE_INTEGER
this fixes #15 and is an alternative to #16 (eg either #16 or #17 should be merged, but not both)

lots of things possibly wrong with this
- i don't know if this works on python2.7
- i don't know if this is a good fix
- i don't know what this might break
- i did not run it through any testsuite (does a testsuite exist? if it does, i am unaware)

however, previously this
```
import ctypes
import ctypes.wintypes
from var_dump import var_dump

foo = ctypes.wintypes.ULARGE_INTEGER(123)
print(foo)
var_dump(foo)
```
would produce
```
c_ulonglong(123)
#0 object(c_ulonglong) (0)
```
and print() actually did a better job than var_dump() here,
but now it produce:
```
c_ulonglong(123)
#0 object(c_ulonglong(123)) (0)
```
doing at least as good a job as print :)
this also fixes `ctypes.wintypes.HANDLE` which has the same problem as `ctypes.wintypes.ULARGE_INTEGER`
this is an alternative to sha256#16  and fixes sha256#15
@divinity76
Copy link
Author

divinity76 commented May 12, 2022

this has another interesting side effect,
the sample code in README.md (after fixing the tab errors in #18 ) now prints:

#0 object(<__main__.Foo object at 0x00000230C350FEE0>) (6)
    baseProp => tuple(2) 
        [0] => int(33)
        [1] => int(44)
    fl => float(44.33)
    someList => list(2)
        [0] => str(3) "foo"
        [1] => str(3) "goo"
    someTuple => tuple(3)
        [0] => int(33)
        [1] => tuple(2)
            [0] => int(23)
            [1] => int(44)
        [2] => int(55)
    anOb => object(<__main__.Bar object at 0x00000230C350FBE0>) (2)
        barProp => str(18) "I'm from Bar class"
        boo => bool(True)
    no => NoneType(None)

instead of the old

#0 object(Foo) (6)
    baseProp => tuple(2) 
        [0] => int(33)
        [1] => int(44)
    fl => float(44.33)
    someList => list(2)
        [0] => str(3) "foo"
        [1] => str(3) "goo"
    someTuple => tuple(3)
        [0] => int(33)
        [1] => tuple(2)
            [0] => int(23)
            [1] => int(44)
        [2] => int(55)
    anOb => object(Bar) (2)
        barProp => str(18) "I'm from Bar class"
        boo => bool(True)
    no => NoneType(None)

not saying its better or worse, but it certainly is a bit different.
(My personal opinion is that this is an improvement, because now you can see where the class is defined and you can differentiate between __main__.SomeClassWithDuplicateName and SomethingElse.SomeClassWithDuplicateName , but i also see how it contains info that 99% of the time people just don't care about, and perhaps, don't want to see)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

does a bad job with ctypes.wintypes.ULARGE_INTEGER
1 participant