Skip to content

Commit

Permalink
go fmt ... (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
adonovan authored Sep 25, 2024
1 parent 42030a7 commit 1207426
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 79 deletions.
8 changes: 4 additions & 4 deletions internal/chunkedfile/chunkedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
//
// Example:
//
// x = 1 / 0 ### "division by zero"
// ---
// x = 1
// print(x + "") ### "int + string not supported"
// x = 1 / 0 ### "division by zero"
// ---
// x = 1
// print(x + "") ### "int + string not supported"
//
// A client test feeds each chunk of text into the program under test,
// then calls chunk.GotError for each error that actually occurred. Any
Expand Down
74 changes: 37 additions & 37 deletions lib/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,52 @@ import (
// Module math is a Starlark module of math-related functions and constants.
// The module defines the following functions:
//
// ceil(x) - Returns the ceiling of x, the smallest integer greater than or equal to x.
// copysign(x, y) - Returns a value with the magnitude of x and the sign of y.
// fabs(x) - Returns the absolute value of x as float.
// floor(x) - Returns the floor of x, the largest integer less than or equal to x.
// mod(x, y) - Returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.
// pow(x, y) - Returns x**y, the base-x exponential of y.
// remainder(x, y) - Returns the IEEE 754 floating-point remainder of x/y.
// round(x) - Returns the nearest integer, rounding half away from zero.
// ceil(x) - Returns the ceiling of x, the smallest integer greater than or equal to x.
// copysign(x, y) - Returns a value with the magnitude of x and the sign of y.
// fabs(x) - Returns the absolute value of x as float.
// floor(x) - Returns the floor of x, the largest integer less than or equal to x.
// mod(x, y) - Returns the floating-point remainder of x/y. The magnitude of the result is less than y and its sign agrees with that of x.
// pow(x, y) - Returns x**y, the base-x exponential of y.
// remainder(x, y) - Returns the IEEE 754 floating-point remainder of x/y.
// round(x) - Returns the nearest integer, rounding half away from zero.
//
// exp(x) - Returns e raised to the power x, where e = 2.718281… is the base of natural logarithms.
// sqrt(x) - Returns the square root of x.
// exp(x) - Returns e raised to the power x, where e = 2.718281… is the base of natural logarithms.
// sqrt(x) - Returns the square root of x.
//
// acos(x) - Returns the arc cosine of x, in radians.
// asin(x) - Returns the arc sine of x, in radians.
// atan(x) - Returns the arc tangent of x, in radians.
// atan2(y, x) - Returns atan(y / x), in radians.
// The result is between -pi and pi.
// The vector in the plane from the origin to point (x, y) makes this angle with the positive X axis.
// The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct
// quadrant for the angle.
// For example, atan(1) and atan2(1, 1) are both pi/4, but atan2(-1, -1) is -3*pi/4.
// cos(x) - Returns the cosine of x, in radians.
// hypot(x, y) - Returns the Euclidean norm, sqrt(x*x + y*y). This is the length of the vector from the origin to point (x, y).
// sin(x) - Returns the sine of x, in radians.
// tan(x) - Returns the tangent of x, in radians.
// acos(x) - Returns the arc cosine of x, in radians.
// asin(x) - Returns the arc sine of x, in radians.
// atan(x) - Returns the arc tangent of x, in radians.
// atan2(y, x) - Returns atan(y / x), in radians.
// The result is between -pi and pi.
// The vector in the plane from the origin to point (x, y) makes this angle with the positive X axis.
// The point of atan2() is that the signs of both inputs are known to it, so it can compute the correct
// quadrant for the angle.
// For example, atan(1) and atan2(1, 1) are both pi/4, but atan2(-1, -1) is -3*pi/4.
// cos(x) - Returns the cosine of x, in radians.
// hypot(x, y) - Returns the Euclidean norm, sqrt(x*x + y*y). This is the length of the vector from the origin to point (x, y).
// sin(x) - Returns the sine of x, in radians.
// tan(x) - Returns the tangent of x, in radians.
//
// degrees(x) - Converts angle x from radians to degrees.
// radians(x) - Converts angle x from degrees to radians.
// degrees(x) - Converts angle x from radians to degrees.
// radians(x) - Converts angle x from degrees to radians.
//
// acosh(x) - Returns the inverse hyperbolic cosine of x.
// asinh(x) - Returns the inverse hyperbolic sine of x.
// atanh(x) - Returns the inverse hyperbolic tangent of x.
// cosh(x) - Returns the hyperbolic cosine of x.
// sinh(x) - Returns the hyperbolic sine of x.
// tanh(x) - Returns the hyperbolic tangent of x.
// acosh(x) - Returns the inverse hyperbolic cosine of x.
// asinh(x) - Returns the inverse hyperbolic sine of x.
// atanh(x) - Returns the inverse hyperbolic tangent of x.
// cosh(x) - Returns the hyperbolic cosine of x.
// sinh(x) - Returns the hyperbolic sine of x.
// tanh(x) - Returns the hyperbolic tangent of x.
//
// log(x, base) - Returns the logarithm of x in the given base, or natural logarithm by default.
// log(x, base) - Returns the logarithm of x in the given base, or natural logarithm by default.
//
// gamma(x) - Returns the Gamma function of x.
// gamma(x) - Returns the Gamma function of x.
//
// All functions accept both int and float values as arguments.
//
// The module also defines approximations of the following constants:
//
// e - The base of natural logarithms, approximately 2.71828.
// pi - The ratio of a circle's circumference to its diameter, approximately 3.14159.
//
// e - The base of natural logarithms, approximately 2.71828.
// pi - The ratio of a circle's circumference to its diameter, approximately 3.14159.
var Module = &starlarkstruct.Module{
Name: "math",
Members: starlark.StringDict{
Expand Down Expand Up @@ -146,7 +145,8 @@ func newBinaryBuiltin(name string, fn func(float64, float64) float64) *starlark.
})
}

// log wraps the Log function
// log wraps the Log function
//
// as a Starlark built-in that accepts int or float arguments.
func log(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
var (
Expand Down
62 changes: 29 additions & 33 deletions lib/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
//
// This package defines several types of Starlark value:
//
// Message -- a protocol message
// RepeatedField -- a repeated field of a message, like a list
// Message -- a protocol message
// RepeatedField -- a repeated field of a message, like a list
//
// FileDescriptor -- information about a .proto file
// FieldDescriptor -- information about a message field (or extension field)
// MessageDescriptor -- information about the type of a message
// EnumDescriptor -- information about an enumerated type
// EnumValueDescriptor -- a value of an enumerated type
// FileDescriptor -- information about a .proto file
// FieldDescriptor -- information about a message field (or extension field)
// MessageDescriptor -- information about the type of a message
// EnumDescriptor -- information about an enumerated type
// EnumValueDescriptor -- a value of an enumerated type
//
// A Message value is a wrapper around a protocol message instance.
// Starlark programs may access and update Messages using dot notation:
//
// x = msg.field
// msg.field = x + 1
// msg.field += 1
// x = msg.field
// msg.field = x + 1
// msg.field += 1
//
// Assignments to message fields perform dynamic checks on the type and
// range of the value to ensure that the message is at all times valid.
Expand All @@ -35,31 +35,30 @@
// performs a dynamic check to ensure that the RepeatedField holds
// only elements of the correct type.
//
// type(msg.uint32s) # "proto.repeated<uint32>"
// msg.uint32s[0] = 1
// msg.uint32s[0] = -1 # error: invalid uint32: -1
// type(msg.uint32s) # "proto.repeated<uint32>"
// msg.uint32s[0] = 1
// msg.uint32s[0] = -1 # error: invalid uint32: -1
//
// Any iterable may be assigned to a repeated field of a message. If
// the iterable is itself a value of type RepeatedField, the message
// field holds a reference to it.
//
// msg2.uint32s = msg.uint32s # both messages share one RepeatedField
// msg.uint32s[0] = 123
// print(msg2.uint32s[0]) # "123"
// msg2.uint32s = msg.uint32s # both messages share one RepeatedField
// msg.uint32s[0] = 123
// print(msg2.uint32s[0]) # "123"
//
// The RepeatedFields' element types must match.
// It is not enough for the values to be merely valid:
//
// msg.uint32s = [1, 2, 3] # makes a copy
// msg.uint64s = msg.uint32s # error: repeated field has wrong type
// msg.uint64s = list(msg.uint32s) # ok; makes a copy
// msg.uint32s = [1, 2, 3] # makes a copy
// msg.uint64s = msg.uint32s # error: repeated field has wrong type
// msg.uint64s = list(msg.uint32s) # ok; makes a copy
//
// For all other iterables, a new RepeatedField is constructed from the
// elements of the iterable.
//
// msg.uints32s = [1, 2, 3]
// print(type(msg.uints32s)) # "proto.repeated<uint32>"
//
// msg.uints32s = [1, 2, 3]
// print(type(msg.uints32s)) # "proto.repeated<uint32>"
//
// To construct a Message from encoded binary or text data, call
// Unmarshal or UnmarshalText. These two functions are exposed to
Expand All @@ -75,7 +74,6 @@
//
// See proto_test.go for an example of how to use the 'proto'
// module in an application that embeds Starlark.
//
package proto

// TODO(adonovan): Go and Starlark API improvements:
Expand Down Expand Up @@ -111,8 +109,8 @@ import (
// for a Starlark thread to use this package.
//
// For example:
// SetPool(thread, protoregistry.GlobalFiles)
//
// SetPool(thread, protoregistry.GlobalFiles)
func SetPool(thread *starlark.Thread, pool DescriptorPool) {
thread.SetLocal(contextKey, pool)
}
Expand Down Expand Up @@ -305,10 +303,9 @@ func getFieldStarlark(thread *starlark.Thread, fn *starlark.Builtin, args starla
// When a message descriptor is called, it returns a new instance of the
// protocol message it describes.
//
// Message(msg) -- return a shallow copy of an existing message
// Message(k=v, ...) -- return a new message with the specified fields
// Message(dict(...)) -- return a new message with the specified fields
//
// Message(msg) -- return a shallow copy of an existing message
// Message(k=v, ...) -- return a new message with the specified fields
// Message(dict(...)) -- return a new message with the specified fields
func (d MessageDescriptor) CallInternal(thread *starlark.Thread, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
dest := &Message{
msg: newMessage(d.Desc),
Expand Down Expand Up @@ -1219,11 +1216,10 @@ func enumValueOf(enum protoreflect.EnumDescriptor, x starlark.Value) (protorefle
//
// An EnumValueDescriptor has the following fields:
//
// index -- int, index of this value within the enum sequence
// name -- string, name of this enum value
// number -- int, numeric value of this enum value
// type -- EnumDescriptor, the enum type to which this value belongs
//
// index -- int, index of this value within the enum sequence
// name -- string, name of this enum value
// number -- int, numeric value of this enum value
// type -- EnumDescriptor, the enum type to which this value belongs
type EnumValueDescriptor struct {
Desc protoreflect.EnumValueDescriptor
}
Expand Down
8 changes: 3 additions & 5 deletions starlarkstruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

// Package starlarkstruct defines the Starlark types 'struct' and
// 'module', both optional language extensions.
//
package starlarkstruct // import "go.starlark.net/starlarkstruct"

// It is tempting to introduce a variant of Struct that is a wrapper
Expand Down Expand Up @@ -36,10 +35,9 @@ import (
//
// An application can add 'struct' to the Starlark environment like so:
//
// globals := starlark.StringDict{
// "struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
// }
//
// globals := starlark.StringDict{
// "struct": starlark.NewBuiltin("struct", starlarkstruct.Make),
// }
func Make(_ *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
if len(args) > 0 {
return nil, fmt.Errorf("struct: unexpected positional arguments")
Expand Down

0 comments on commit 1207426

Please sign in to comment.