-
Notifications
You must be signed in to change notification settings - Fork 60
Fix format specifier #99
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
Conversation
Please verify that I implemented to the GPS coordinates correctly! |
@AMInnovationTeam Want to test this? |
easiest option would be after that, this should be removed, since it's superfluous:
|
That's what pyupgrade would do: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 70ade69..78c8c61 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -7,6 +7,12 @@ repos:
rev: 23.3.0
hooks:
- id: black
+ - repo: https://github.com/asottile/pyupgrade
+ rev: v3.4.0
+ hooks:
+ - id: pyupgrade
+ args:
+ - --py37-plus
- repo: https://github.com/fsfe/reuse-tool
rev: v1.1.2
hooks:
diff --git a/adafruit_gps.py b/adafruit_gps.py
index e97ca46..b727c94 100644
--- a/adafruit_gps.py
+++ b/adafruit_gps.py
@@ -370,7 +370,7 @@ class GPS:
for char in command:
checksum ^= char
self.write(b"*")
- self.write(bytes("{:02x}".format(checksum).upper(), "ascii"))
+ self.write(bytes(f"{checksum:02x}".upper(), "ascii"))
self.write(b"\r\n")
@property
@@ -626,7 +626,7 @@ class GPS:
satlist = list(filter(None, data[2:-4]))
self.sat_prns = []
for sat in satlist:
- self.sat_prns.append("{}{}".format(talker, sat))
+ self.sat_prns.append(f"{talker}{sat}")
# PDOP, dilution of precision
self.pdop = _parse_float(data[14])
@@ -671,7 +671,7 @@ class GPS:
j = i * 4
value = (
# Satellite number
- "{}{}".format(talker, sat_tup[0 + j]),
+ f"{talker}{sat_tup[0 + j]}",
# Elevation in degrees
sat_tup[1 + j],
# Azimuth in degrees
diff --git a/docs/conf.py b/docs/conf.py
index ab83199..6ae5711 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
#
# SPDX-License-Identifier: MIT
diff --git a/examples/gps_simpletest.py b/examples/gps_simpletest.py
index 6434f27..b9ef922 100644
--- a/examples/gps_simpletest.py
+++ b/examples/gps_simpletest.py
@@ -82,8 +82,8 @@ while True:
gps.timestamp_utc.tm_sec,
)
)
- print("Latitude: {0:.6f} degrees".format(gps.latitude))
- print("Longitude: {0:.6f} degrees".format(gps.longitude))
+ print(f"Latitude: {gps.latitude:.6f} degrees")
+ print(f"Longitude: {gps.longitude:.6f} degrees")
print(
"Precise Latitude: {:3.0f} degs, {:2.4f} mins".format(
math.floor(gps.latitude_degrees), gps.latitude_minutes
@@ -94,18 +94,18 @@ while True:
math.floor(gps.longitude_degrees), gps.longitude_minutes
)
)
- print("Fix quality: {}".format(gps.fix_quality))
+ print(f"Fix quality: {gps.fix_quality}")
# Some attributes beyond latitude, longitude and timestamp are optional
# and might not be present. Check if they're None before trying to use!
if gps.satellites is not None:
- print("# satellites: {}".format(gps.satellites))
+ print(f"# satellites: {gps.satellites}")
if gps.altitude_m is not None:
- print("Altitude: {} meters".format(gps.altitude_m))
+ print(f"Altitude: {gps.altitude_m} meters")
if gps.speed_knots is not None:
- print("Speed: {} knots".format(gps.speed_knots))
+ print(f"Speed: {gps.speed_knots} knots")
if gps.track_angle_deg is not None:
- print("Track angle: {} degrees".format(gps.track_angle_deg))
+ print(f"Track angle: {gps.track_angle_deg} degrees")
if gps.horizontal_dilution is not None:
- print("Horizontal dilution: {}".format(gps.horizontal_dilution))
+ print(f"Horizontal dilution: {gps.horizontal_dilution}")
if gps.height_geoid is not None:
- print("Height geoid: {} meters".format(gps.height_geoid))
+ print(f"Height geoid: {gps.height_geoid} meters")
diff --git a/examples/gps_time_source.py b/examples/gps_time_source.py
index 0199ca5..baf4714 100644
--- a/examples/gps_time_source.py
+++ b/examples/gps_time_source.py
@@ -47,12 +47,12 @@ while True:
print("No time data from GPS yet")
continue
# Time & date from GPS informations
- print("Fix timestamp: {}".format(_format_datetime(gps.timestamp_utc)))
+ print(f"Fix timestamp: {_format_datetime(gps.timestamp_utc)}")
# Time & date from internal RTC
- print("RTC timestamp: {}".format(_format_datetime(the_rtc.datetime)))
+ print(f"RTC timestamp: {_format_datetime(the_rtc.datetime)}")
# Time & date from time.localtime() function
local_time = time.localtime()
- print("Local time: {}".format(_format_datetime(local_time)))
+ print(f"Local time: {_format_datetime(local_time)}") |
Hi @dhalbert, I tested it but I don't think the names described in the string are accurate. For example, it provides the output in "Degrees" and "Minutes". When I ask an online calculate to do the conversion, it provides a different "Minute" output. |
@jkittner if you want to merge in changes from this PR into yours, I can close this one. Or would you prefer me to merge now? |
Closing in favor of #102 |
Fixes #95
Should switch to using f-strings at some point, but wanted to submit a quick fix for the issue.