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

Python3 Support #87

Merged
merged 20 commits into from
Dec 17, 2019
Merged

Python3 Support #87

merged 20 commits into from
Dec 17, 2019

Conversation

TrystanLea
Copy link
Member

Pull request to help with testing

- Standard library imports should go first.
- Remove unused or duplicate imports.
- expr == False -> not expr
- expr == True -> expr (or expr is True, if the type isn't clear).
- not x in y => x not in y
- not x == "1" => x != "1"
- omit range default
- 'if not x or not y: pass else: z' => 'if x and y: z'
- str.__len__ => len
- x > 1 and x < 10 => 1 < x < 10
- not x > y => x <= y
- if x: if y: if z: _ => if x and y and x: _
- BUGFIX: "a" and "b" in f => all(i in f for i in ["a","b"])
- BUGFIX: .lower => .lower()
- defaultdict to avoid initialising every entry up front
- Use struct.calcsize instead of copying the values.
- if x == 0: y = False: else y = True => y = bool(x)
- list[len(list)-1] => list[-1]
- math.pow(256, 1) => 0x08 etc.
- x = bytearray(); x.append(y); x.append(z) => x = bytearray([y, z])
- value = x; return value => return x
- Create dicts at compile time.
- Use startswith as it's less error prone.
- Add some FIXMEs.
- Make dict at compile time.
- Use enumerate.
- Lift sum out of if blocks.
It's much easier to use and it didn't change from python2 to python3.

I can't easily test PacketGen, though, but it seems to be unused.
We were passing a string where an integer port number was expected. Add
a cast.
This code shouldn't really be relying on division, but change it to
return an integer anyway.
@TrystanLea TrystanLea changed the base branch from emon-pi to python3 December 17, 2019 20:07
@TrystanLea TrystanLea merged commit c5838f1 into openenergymonitor:python3 Dec 17, 2019
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.

5 participants